﻿namespace Sidvall.WorkItemManager.Net.Services.V1
{
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling")]
    public sealed partial class MonitorContext : global::Sidvall.Data.ServiceDataRowBase, global::Sidvall.WorkItemManager.Data.IMonitorContext
    {
        #region Public Members

        #region BccRecipientAddresses

        private string _BccRecipientAddresses;
        partial void OnBeforeBccRecipientAddressesPropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterBccRecipientAddressesPropertyChanged();
        public string BccRecipientAddresses
        { 
            get
            {
                return _BccRecipientAddresses;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _BccRecipientAddresses = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _BccRecipientAddresses);
                    OnBeforeBccRecipientAddressesPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("BccRecipientAddresses", eventData.Value, true, true);
                        OnAfterBccRecipientAddressesPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region Body

        private string _Body;
        partial void OnBeforeBodyPropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterBodyPropertyChanged();
        public string Body
        { 
            get
            {
                return _Body;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _Body = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _Body);
                    OnBeforeBodyPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("Body", eventData.Value, true, true);
                        OnAfterBodyPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region CCRecipientAddresses

        private string _CCRecipientAddresses;
        partial void OnBeforeCCRecipientAddressesPropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterCCRecipientAddressesPropertyChanged();
        public string CCRecipientAddresses
        { 
            get
            {
                return _CCRecipientAddresses;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _CCRecipientAddresses = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _CCRecipientAddresses);
                    OnBeforeCCRecipientAddressesPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("CCRecipientAddresses", eventData.Value, true, true);
                        OnAfterCCRecipientAddressesPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region ConnectionString

        private string _ConnectionString;
        partial void OnBeforeConnectionStringPropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterConnectionStringPropertyChanged();
        public string ConnectionString
        { 
            get
            {
                return _ConnectionString;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _ConnectionString = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _ConnectionString);
                    OnBeforeConnectionStringPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("ConnectionString", eventData.Value, true, true);
                        OnAfterConnectionStringPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region ConnectionTypeId

        private global::Sidvall.WorkItemManager.Data.ConnectionType _ConnectionTypeId;
        partial void OnBeforeConnectionTypeIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<global::Sidvall.WorkItemManager.Data.ConnectionType> eventData);
        partial void OnAfterConnectionTypeIdPropertyChanged();
        public global::Sidvall.WorkItemManager.Data.ConnectionType ConnectionTypeId
        { 
            get
            {
                return _ConnectionTypeId;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _ConnectionTypeId = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<global::Sidvall.WorkItemManager.Data.ConnectionType> eventData = new Sidvall.Business.PropertyChangeEventData<global::Sidvall.WorkItemManager.Data.ConnectionType>(value, _ConnectionTypeId);
                    OnBeforeConnectionTypeIdPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("ConnectionTypeId", eventData.Value, true, true);
                        OnAfterConnectionTypeIdPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region FromAddress

        private string _FromAddress;
        partial void OnBeforeFromAddressPropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterFromAddressPropertyChanged();
        public string FromAddress
        { 
            get
            {
                return _FromAddress;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _FromAddress = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _FromAddress);
                    OnBeforeFromAddressPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("FromAddress", eventData.Value, true, true);
                        OnAfterFromAddressPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region IsBodyHtml

        private bool _IsBodyHtml;
        partial void OnBeforeIsBodyHtmlPropertyChanged(Sidvall.Business.PropertyChangeEventData<bool> eventData);
        partial void OnAfterIsBodyHtmlPropertyChanged();
        public bool IsBodyHtml
        { 
            get
            {
                return _IsBodyHtml;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _IsBodyHtml = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<bool> eventData = new Sidvall.Business.PropertyChangeEventData<bool>(value, _IsBodyHtml);
                    OnBeforeIsBodyHtmlPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("IsBodyHtml", eventData.Value, true, true);
                        OnAfterIsBodyHtmlPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region MobileNumber

        private string _MobileNumber;
        partial void OnBeforeMobileNumberPropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterMobileNumberPropertyChanged();
        public string MobileNumber
        { 
            get
            {
                return _MobileNumber;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _MobileNumber = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _MobileNumber);
                    OnBeforeMobileNumberPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("MobileNumber", eventData.Value, true, true);
                        OnAfterMobileNumberPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region MonitorContextId

        private System.Nullable<int> _MonitorContextId;
        partial void OnBeforeMonitorContextIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<System.Nullable<int>> eventData);
        partial void OnAfterMonitorContextIdPropertyChanged();
        public System.Nullable<int> MonitorContextId
        { 
            get
            {
                return _MonitorContextId;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _MonitorContextId = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<System.Nullable<int>> eventData = new Sidvall.Business.PropertyChangeEventData<System.Nullable<int>>(value, _MonitorContextId);
                    OnBeforeMonitorContextIdPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("MonitorContextId", eventData.Value, true, true);
                        OnAfterMonitorContextIdPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region RecipientAddresses

        private string _RecipientAddresses;
        partial void OnBeforeRecipientAddressesPropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterRecipientAddressesPropertyChanged();
        public string RecipientAddresses
        { 
            get
            {
                return _RecipientAddresses;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _RecipientAddresses = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _RecipientAddresses);
                    OnBeforeRecipientAddressesPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("RecipientAddresses", eventData.Value, true, true);
                        OnAfterRecipientAddressesPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region RemoteAddress

        private string _RemoteAddress;
        partial void OnBeforeRemoteAddressPropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterRemoteAddressPropertyChanged();
        public string RemoteAddress
        { 
            get
            {
                return _RemoteAddress;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _RemoteAddress = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _RemoteAddress);
                    OnBeforeRemoteAddressPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("RemoteAddress", eventData.Value, true, true);
                        OnAfterRemoteAddressPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region SmsBody

        private string _SmsBody;
        partial void OnBeforeSmsBodyPropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterSmsBodyPropertyChanged();
        public string SmsBody
        { 
            get
            {
                return _SmsBody;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _SmsBody = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _SmsBody);
                    OnBeforeSmsBodyPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("SmsBody", eventData.Value, true, true);
                        OnAfterSmsBodyPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region SmsWebAddress

        private string _SmsWebAddress;
        partial void OnBeforeSmsWebAddressPropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterSmsWebAddressPropertyChanged();
        public string SmsWebAddress
        { 
            get
            {
                return _SmsWebAddress;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _SmsWebAddress = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _SmsWebAddress);
                    OnBeforeSmsWebAddressPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("SmsWebAddress", eventData.Value, true, true);
                        OnAfterSmsWebAddressPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region SmtpServer

        private string _SmtpServer;
        partial void OnBeforeSmtpServerPropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterSmtpServerPropertyChanged();
        public string SmtpServer
        { 
            get
            {
                return _SmtpServer;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _SmtpServer = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _SmtpServer);
                    OnBeforeSmtpServerPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("SmtpServer", eventData.Value, true, true);
                        OnAfterSmtpServerPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region Subject

        private string _Subject;
        partial void OnBeforeSubjectPropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterSubjectPropertyChanged();
        public string Subject
        { 
            get
            {
                return _Subject;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _Subject = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _Subject);
                    OnBeforeSubjectPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("Subject", eventData.Value, true, true);
                        OnAfterSubjectPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region DataRowContextStorageKey

        protected override string DataRowContextStorageKey
        {
            get
            {
                return global::Sidvall.WorkItemManager.SystemContextConfig.Current.EntityFacade.MonitorContextManager.GetKey(this);
            }
        }

        #endregion
        #region DataRowStateIsDirty

        protected override bool DataRowStateIsDirty
        {
            get
            {
                return global::Sidvall.WorkItemManager.SystemContextConfig.Current.EntityFacade.MonitorContextManager.DataRowStateIsDirty(this);
            }
        }

        #endregion
        
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
        public MonitoredWorkItemCollectionItem MonitoredWorkItems { get; set; }
        #region LoadMonitoredWorkItems

        public void LoadMonitoredWorkItems(MonitoredWorkItemCollectionItem value)
        {
            LoadInstanceField("MonitoredWorkItems", value, true, false);
        }

        #endregion
        #region LoadInstanceField

        public void LoadInstanceField(string fieldName, object value, bool cascade, bool updateState)
        {
            global::Sidvall.WorkItemManager.SystemContextConfig.Current.EntityFacade.MonitorContextManager.LoadInstanceField(this, fieldName, value, cascade, false, updateState);
        }

        #endregion
        #region Copy

        public MonitorContext Copy()
        {
            return global::Sidvall.WorkItemManager.SystemContextConfig.Current.EntityFacade.MonitorContextManager.Copy(this);
        }
        public MonitorContext Copy(Sidvall.Data.CopySettings settings)
        {
            return global::Sidvall.WorkItemManager.SystemContextConfig.Current.EntityFacade.MonitorContextManager.Copy(this, settings);
        }

        #endregion
        #region Import

        public void Import(global::Sidvall.WorkItemManager.Data.IMonitorContext item)
        {
            global::Sidvall.WorkItemManager.SystemContextConfig.Current.EntityFacade.MonitorContextManager.Import(this, item);
        }
        public void Import(global::Sidvall.WorkItemManager.Data.IMonitorContext item, Sidvall.Data.CopySettings settings)
        {
            global::Sidvall.WorkItemManager.SystemContextConfig.Current.EntityFacade.MonitorContextManager.Import(this, item, settings);
        }

        #endregion
        #region ValidateAsync

        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync()
        {
            return await global::Sidvall.WorkItemManager.SystemContextConfig.Current.EntityFacade.MonitorContextManager.ValidateAsync(this).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync(Sidvall.Data.ValidationSettings settings)
        {
            return await global::Sidvall.WorkItemManager.SystemContextConfig.Current.EntityFacade.MonitorContextManager.ValidateAsync(this, settings).ConfigureAwait(false);
        }

        #endregion
        #region Initialize

        public void Initialize()
        {
            global::Sidvall.WorkItemManager.SystemContextConfig.Current.EntityFacade.MonitorContextManager.Initialize(this);
        }
        public void Initialize(Sidvall.Data.InitializeSettings settings)
        {
            global::Sidvall.WorkItemManager.SystemContextConfig.Current.EntityFacade.MonitorContextManager.Initialize(this, settings);
        }

        #endregion

        #region IMonitorContext Members

        string global::Sidvall.WorkItemManager.Data.IMonitorContext.BccRecipientAddresses
        {
            get
            {
                return this._BccRecipientAddresses;
            }
            set
            {
                this._BccRecipientAddresses = value;
            }
        }
        string global::Sidvall.WorkItemManager.Data.IMonitorContext.Body
        {
            get
            {
                return this._Body;
            }
            set
            {
                this._Body = value;
            }
        }
        string global::Sidvall.WorkItemManager.Data.IMonitorContext.CCRecipientAddresses
        {
            get
            {
                return this._CCRecipientAddresses;
            }
            set
            {
                this._CCRecipientAddresses = value;
            }
        }
        string global::Sidvall.WorkItemManager.Data.IMonitorContext.ConnectionString
        {
            get
            {
                return this._ConnectionString;
            }
            set
            {
                this._ConnectionString = value;
            }
        }
        global::Sidvall.WorkItemManager.Data.ConnectionType global::Sidvall.WorkItemManager.Data.IMonitorContext.ConnectionTypeId
        {
            get
            {
                return this._ConnectionTypeId;
            }
            set
            {
                this._ConnectionTypeId = value;
            }
        }
        string global::Sidvall.WorkItemManager.Data.IMonitorContext.FromAddress
        {
            get
            {
                return this._FromAddress;
            }
            set
            {
                this._FromAddress = value;
            }
        }
        bool global::Sidvall.WorkItemManager.Data.IMonitorContext.IsBodyHtml
        {
            get
            {
                return this._IsBodyHtml;
            }
            set
            {
                this._IsBodyHtml = value;
            }
        }
        string global::Sidvall.WorkItemManager.Data.IMonitorContext.MobileNumber
        {
            get
            {
                return this._MobileNumber;
            }
            set
            {
                this._MobileNumber = value;
            }
        }
        System.Nullable<int> global::Sidvall.WorkItemManager.Data.IMonitorContext.MonitorContextId
        {
            get
            {
                return this._MonitorContextId;
            }
            set
            {
                this._MonitorContextId = value;
            }
        }
        string global::Sidvall.WorkItemManager.Data.IMonitorContext.RecipientAddresses
        {
            get
            {
                return this._RecipientAddresses;
            }
            set
            {
                this._RecipientAddresses = value;
            }
        }
        string global::Sidvall.WorkItemManager.Data.IMonitorContext.RemoteAddress
        {
            get
            {
                return this._RemoteAddress;
            }
            set
            {
                this._RemoteAddress = value;
            }
        }
        string global::Sidvall.WorkItemManager.Data.IMonitorContext.SmsBody
        {
            get
            {
                return this._SmsBody;
            }
            set
            {
                this._SmsBody = value;
            }
        }
        string global::Sidvall.WorkItemManager.Data.IMonitorContext.SmsWebAddress
        {
            get
            {
                return this._SmsWebAddress;
            }
            set
            {
                this._SmsWebAddress = value;
            }
        }
        string global::Sidvall.WorkItemManager.Data.IMonitorContext.SmtpServer
        {
            get
            {
                return this._SmtpServer;
            }
            set
            {
                this._SmtpServer = value;
            }
        }
        string global::Sidvall.WorkItemManager.Data.IMonitorContext.Subject
        {
            get
            {
                return this._Subject;
            }
            set
            {
                this._Subject = value;
            }
        }
        System.Collections.Generic.IEnumerable<global::Sidvall.WorkItemManager.Data.IMonitoredWorkItem> global::Sidvall.WorkItemManager.Data.IMonitorContext.MonitoredWorkItems
        {
            get
            {
                if (this.MonitoredWorkItems != null)
                    return this.MonitoredWorkItems.Items;
                return null;
            }
        }
        void global::Sidvall.WorkItemManager.Data.IMonitorContext.SetMonitoredWorkItems(Sidvall.Data.IDataRowProvider<global::Sidvall.WorkItemManager.Data.IMonitoredWorkItem> items)
        {
            this.MonitoredWorkItems = (MonitoredWorkItemCollectionItem)items;
        }

        #endregion

        #endregion
        #region Constructors

        public MonitorContext()
        {
        }
        public MonitorContext(bool initializeDefaultValues)
            : this(initializeDefaultValues, null, Sidvall.Business.BusinessEvents.None)
        {
        }
        public MonitorContext(bool initializeDefaultValues, Sidvall.Data.DataRowState? dataRowState, Sidvall.Business.BusinessEvents enabledBusinessEvents)
            : base(dataRowState, enabledBusinessEvents)
        {
            if (initializeDefaultValues)
                global::Sidvall.WorkItemManager.SystemContextConfig.Current.EntityFacade.MonitorContextManager.Initialize(this);
        }

        #endregion
    }
}